package com.mtt.thirdapi.yanxuan.controller;

import com.mtt.thirdapi.yanxuan.service.YXOpenApiService;
import com.mtt.thirdapi.common.api.R;
import com.mtt.thirdapi.yanxuan.vo.OrderVO;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 *
 */
@RestController
@RequestMapping("yanxuan")
@Slf4j
public class YXTradingController {
    @Autowired
    YXOpenApiService yxOpenApiService;

    /**
     * 渠道下单接口   用户付款后，渠道把订单信息推给严选，严选再发货给用户 目前自是个实例，实用需要优化
     * @param order
     * @return
     */
    @PostMapping("paidOrder")
    public R pavedOrder(@RequestBody OrderVO order){
        return yxOpenApiService.handlePaidOrder(order);
    }

    /**
     * 取消订单接口   订单发货前，用户申请取消订单时，渠道把取消操作推给严选。
     * @param orderId  订单号
     * @return
     */
    @PostMapping("/cancelOrder")
    public R cacelOrder(@RequestParam(value = "orderId") String orderId){
        return yxOpenApiService.handleCancelOrder(orderId);
    }

    /**
     * 渠道订单确认收货接口   用户确认收货后，渠道把确认收货信息推给严选
     * @param orderId  订单号
     * @param packageId  订单包裹号
     * @param confirmTime  签收时间  2016-05-23 16:32:48
     * @return
     */
    @PostMapping("/confirmOrder")
    public R confirmOrder(
            @RequestParam(value = "orderId") String orderId,
            @RequestParam(value="packageId",required = false) String packageId,
            @RequestParam(value = "confirmTime",required = false) String confirmTime){
        return yxOpenApiService.handleConfirmOrder(orderId,packageId,confirmTime);
    }


    /**
     * 渠道订单信息查询接口
     * @param orderId
     * @return
     */
    @GetMapping("/getOrder")
    public R getOrder(@RequestParam(value = "orderId") String orderId){
        return yxOpenApiService.handleGetOrder(orderId);
    }
}
